package com.bwie.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbOrder;
import com.bwie.pojo.TbUser;
import com.bwie.service.IUserService;
import com.bwie.service.TbOrderService;
import com.bwie.mapper.TbOrderMapper;
import com.bwie.utils.R;
import feign.RequestTemplate;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
* @author 31803
* @description 针对表【tb_order(订单表)】的数据库操作Service实现
* @createDate 2025-04-21 16:30:59
*/
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder>
    implements TbOrderService{

    @Autowired
    TbOrderMapper tbOrderMapper;

    @Autowired
    RestTemplate restTemplate;
    @Autowired
    IUserService iUserService;

    public R getOrderByid(Integer orderId) {
        TbOrder tbOrder = tbOrderMapper.selectById(orderId);
        if(tbOrder==null){
            return R.ERROR(500,"订单不存在");
        }

//        String url="http://localhost:9001/user/index/getUserByid/"+tbOrder.getUserId();
//
//        R r = restTemplate.postForObject(url, null,R.class);

        R r = iUserService.getUserByid(tbOrder.getUserId());

        String user = JSON.toJSONString(r.getData());

        TbUser tbuser1 = JSON.parseObject(user, TbUser.class);


        tbOrder.setUser(tbuser1);
        return R.OK(tbOrder);
    }
}




